/**
 * Copyright (c) 2013-2022 Nikita Koksharov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.client.protocol.convertor;


/**
 * 实现了将对象转换为Boolean类型逻辑的转换器。
 * 该转换器主要用于处理特定的转换逻辑，将特定的对象转换为Boolean值。
 */
public class BooleanReplayConvertor implements Convertor<Boolean> {

    /**
     * 将给定的对象转换为Boolean类型。
     * 转换逻辑基于对象是否等于Long类型的1或字符串"OK"。
     *
     * @param obj 待转换的对象。
     * @return 转换后的Boolean值。如果obj为null，则返回null；如果obj等于Long类型的1或字符串"OK"，则返回true；否则返回false。
     */
    @Override
    public Boolean convert(Object obj) {
        if (obj == null) {
            return null;
        }
        // 判断obj是否等于1（Long类型）或"OK"（String类型），是则返回true，否则返回false
        return Long.valueOf(1).equals(obj) || "OK".equals(obj);
    }
}
